<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Admin_SettingsController extends Zend_Rest_Controller{
    private $_mapper;
    public function init(){
        parent::init();
		$b = $this->getInvokeArg('bootstrap');
        if (!$b->hasOption('settingsfile'))
            throw new Zend_Exception("settingsfile wasn't specified in application.ini");
        $this->_mapper = new Admin_Model_SettingsMapper('/configs/'.$b->getOption('settingsfile'));
    }
    public function indexAction(){
        $content = $this->_mapper->getSettingsAsJSON();
        $this->_helper->layout->disableLayout();
        $response = Zend_Controller_Front::getInstance()->getResponse();
        $response->setHeader('Content-Type', 'application/json', true);
        $this->_helper->viewRenderer->setNoRender(true);
        echo $content;
    }
    public function getAction(){
    }
    public function putAction(){
        $request = $this->getRequest();
        $this->_mapper->setSettingsAsJSON($request->getRawBody());
    	$this->_helper->json(array('success'=>true, 'msg'=>'Настройки сохранены'));
    }
    public function postAction(){
    }
    public function deleteAction(){
    }
}
?>
